#!/bin/sh
################################################################################
# acpi
################################################################################
. /etc/rc.d/functions

start() {

    /usr/bin/logger -s -t minimyth -p "local0.info" "[init.d/acpi] Starting..."

    /bin/echo ${MM_ACPI_VIDEO_FLAGS} > /proc/sys/kernel/acpi_video_flags

    case "${MM_ACPI_EVENT_BUTTON_POWER}" in
        off)
            /bin/sed -e 's%@MM_ACPI_EVENT_BUTTON_POWER@%/sbin/poweroff%'    -i /etc/acpi/events/power
            ;;
        sleep)
            /bin/sed -e 's%@MM_ACPI_EVENT_BUTTON_POWER@%/usr/bin/mm_sleep%' -i /etc/acpi/events/power
            ;;
    esac

    /usr/sbin/acpid

    if [ "x${MM_ACPI_WOL_ENABLED}" = "xyes" ] ; then
        /usr/sbin/ethtool -s "${MM_ACPI_WOL_INTF}" wol g
        /bin/echo MMAC > /proc/acpi/wakeup
        /usr/bin/logger -t minimyth -p "local0.info" "[init.d/acpi] Enabling Wake-on-LAN on ${MM_ACPI_WOL_INTF} interface..."
    fi

    /usr/bin/logger -s -t minimyth -p "local0.info" "[init.d/acpi] Started with return code=0..."

    return 0
}

stop() {
    mm_message_output info "stopping ACPI ..."

    if [ -n "`/bin/pidof acpid`" ] ; then
        /usr/bin/killall acpid
    fi

    return 0
}

case $1 in
    start) start ;;
    stop)  stop  ;;
esac

exit 0
